Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented date #38

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Implemented date #38

wants to merge 8 commits into from

Conversation

Eike-Flath
Copy link
Contributor

@Eike-Flath Eike-Flath commented Apr 21, 2024

I implemented date (issue #6) as described by the POSIX standard.
I did implement support for changing the system time.
I did not implement any features that are not described in the POSIX standard.

src/date/date.c Show resolved Hide resolved
@proh14
Copy link
Owner

proh14 commented Apr 23, 2024

hello thanks for your contribution! please also add --help + some of the gnu flags

@Eike-Flath Eike-Flath marked this pull request as draft April 27, 2024 18:58
@Eike-Flath Eike-Flath marked this pull request as ready for review April 28, 2024 17:01
@Eike-Flath
Copy link
Contributor Author

@proh14 I now added --help as well as the GNU flags --iso-8601, --rfc-3339, and --rfc-email (as well as their short option equivalents). I also added support for the GNU format specifiers %N and %:z.
Are there any other GNU features you would like to see implemented?

@@ -1,6 +1,338 @@
#define _POSIX_C_SOURCE 200112L // for setenv
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to create your own setenv. Fear not, it is simpler than it seems.
Take a look at glibc implementaion or muscl one

}
}

#define s(i) (str[i] - '0')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability purposes, you may want to avoid doing define within functions

Comment on lines +101 to +118
static void use_iso_fmt(char *iso) {
if (!strcmp(iso, "hours")) {
set_operand("+%FT%H%:z");
} else if (!strcmp(iso, "minutes")) {
set_operand("+%FT%H:%M%:z");
} else if (!strcmp(iso, "date")) {
set_operand("+%F");
} else if (!strcmp(iso, "seconds")) {
set_operand("+%FT%T%:z");
} else if (!strcmp(iso, "ns")) {
set_operand("+%FT%T,%N%:z");
} else {
fprintf(stderr, "date: invalid argument '%s' for '--iso-8601'\n", iso);
fprintf(stderr,
"must be one of 'hours', 'minutes', 'date', 'seconds', 'ns'\n");
exit(EXIT_FAILURE);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase and move to getopt_long

Comment on lines +156 to +158
static bool strpre(const char *pre, const char *str) {
return !strncmp(pre, str, strlen(pre));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider

Suggested change
static bool strpre(const char *pre, const char *str) {
return !strncmp(pre, str, strlen(pre));
}
#define strpre(pre, str) (!strncmp((pre), (str), sizeof (pre) - 1))

@Eike-Flath Eike-Flath marked this pull request as draft April 29, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants